# -*- coding:utf-8 -*-
# @FileName  :dhcc_ent_resultinfo.py
# @Time      :2020/12/17 16:44
# @Author    :Zhoujirong
# @Desc      :企业辖内查询记录
import time,datetime
from common.log import Log
from biz.cases.base_case import BaseCase
from common.utils import download
from biz.flow.ent_resultinfo import EntResultInfoRequest

class TestEntResultInfo(BaseCase):
    data_file_name = 'ent_resultinfo.yaml'
    @classmethod
    def setUpClass(cls) -> None:
        cls.cookie = BaseCase().get_token()

    def test_a_list(self):
        '''辖内查询记录页跳转'''
        ret = EntResultInfoRequest.list(self.cookie)
        Log.info(ret)
        self.assertIn('辖内查询记录列表',ret)

    def get_page(self):
        '''检索-返回一条数据'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_EQ_enterpriseName = self.file_data.get('search_EQ_enterpriseName')
        search_EQ_signCode = self.file_data.get('search_EQ_signCode')
        search_EQ_uniformSocialCredCode = self.file_data.get('search_EQ_uniformSocialCredCode')
        search_EQ_orgInstCode = self.file_data.get('search_EQ_orgInstCode')
        search_EQ_qryReason = self.file_data.get('search_EQ_qryReason')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_operator = self.file_data.get('search_EQ_operator')
        search_EQ_operOrg = self.file_data.get('search_EQ_operOrg')
        search_EQ_queryFormat = '00'
        search_GTE_LTE_queryTime_DATE_RANGE = '%s - %s'%(datetime.date.today(),datetime.date.today())
        search_EQ_cstmsysId = self.file_data.get('search_EQ_cstmsysId')
        ret = EntResultInfoRequest.get_page(curPage,
                 maxSize,
                 search_EQ_enterpriseName,
                 search_EQ_signCode,
                 search_EQ_uniformSocialCredCode,
                 search_EQ_orgInstCode,
                 search_EQ_qryReason,
                 search_EQ_source,
                 search_EQ_status,
                 search_EQ_operator,
                 search_EQ_operOrg,
                 search_EQ_queryFormat,
                 search_GTE_LTE_queryTime_DATE_RANGE,
                 search_EQ_cstmsysId,self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.list)
        return ret.list[0]

    def detail(self):
        '''跳转详情'''
        id = self.get_page().id
        ret = EntResultInfoRequest.detail(id,self.cookie)
        Log.info(ret)
        self.assertIn('辖内查询记录详情',ret)
        return id

    def test_b_findbyid(self):
        '''跳转详情'''
        id = self.detail()
        ret = EntResultInfoRequest.findbyid(id,self.cookie)
        Log.info(ret)
        self.assertEqual(id,ret.id)

    def get_flag(self):
        '''获取导出标志'''
        search_EQ_enterpriseName = self.file_data.get('search_EQ_enterpriseName')
        search_EQ_signCode = self.file_data.get('search_EQ_signCode')
        search_EQ_uniformSocialCredCode = self.file_data.get('search_EQ_uniformSocialCredCode')
        search_EQ_orgInstCode = self.file_data.get('search_EQ_orgInstCode')
        search_EQ_qryReason = self.file_data.get('search_EQ_qryReason')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_operator = self.file_data.get('search_EQ_operator')
        search_EQ_operOrg = self.file_data.get('search_EQ_operOrg')
        search_EQ_queryFormat = '00'
        search_GTE_LTE_queryTime_DATE_RANGE = '%s - %s' % (datetime.date.today(), datetime.date.today())
        search_EQ_cstmsysId = self.file_data.get('search_EQ_cstmsysId')
        ids = self.get_page().id
        ret = EntResultInfoRequest.get_flag(search_EQ_enterpriseName,
                             search_EQ_signCode,
                             search_EQ_uniformSocialCredCode,
                             search_EQ_orgInstCode,
                             search_EQ_qryReason,
                             search_EQ_source,
                             search_EQ_status,
                             search_EQ_operator,
                             search_EQ_operOrg,
                             search_EQ_queryFormat,
                             search_GTE_LTE_queryTime_DATE_RANGE,
                             search_EQ_cstmsysId,ids,self.cookie)
        Log.info(ret)
        self.assertEqual('允许导出',ret.msg)
        self.assertEqual('00000000',ret.code)

    def test_c_exportload_one(self):
        '''导出一条数据'''
        search_EQ_enterpriseName = self.file_data.get('search_EQ_enterpriseName')
        search_EQ_signCode = self.file_data.get('search_EQ_signCode')
        search_EQ_uniformSocialCredCode = self.file_data.get('search_EQ_uniformSocialCredCode')
        search_EQ_orgInstCode = self.file_data.get('search_EQ_orgInstCode')
        search_EQ_qryReason = self.file_data.get('search_EQ_qryReason')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_operator = self.file_data.get('search_EQ_operator')
        search_EQ_operOrg = self.file_data.get('search_EQ_operOrg')
        search_EQ_queryFormat = '00'
        search_GTE_LTE_queryTime_DATE_RANGE = '%s - %s' % (datetime.date.today(), datetime.date.today())
        search_EQ_cstmsysId = self.file_data.get('search_EQ_cstmsysId')
        ids = self.get_page().id
        ret = EntResultInfoRequest.exportload(search_EQ_enterpriseName,
                             search_EQ_signCode,
                             search_EQ_uniformSocialCredCode,
                             search_EQ_orgInstCode,
                             search_EQ_qryReason,
                             search_EQ_source,
                             search_EQ_status,
                             search_EQ_operator,
                             search_EQ_operOrg,
                             search_EQ_queryFormat,
                             search_GTE_LTE_queryTime_DATE_RANGE,
                             search_EQ_cstmsysId,ids,self.cookie)
        time.sleep(5)
        Log.info(ret)
        name = '企业辖内查询记录1条dhcc_ent_resultinfoDtest_c_exportload_one%s.xls'%time.strftime('%Y%m%d%H%M%S',time.localtime())
        size = download(name,ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)

    def get_page_more(self):
        '''检索-返回多条数据'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_EQ_enterpriseName = ''
        search_EQ_signCode = ''
        search_EQ_uniformSocialCredCode = ''
        search_EQ_qryReason  = ''
        search_EQ_orgInstCode = ''
        search_EQ_source = ''
        search_EQ_status  = ''
        search_EQ_operator  = ''
        search_EQ_operOrg = ''
        search_EQ_queryFormat = ''
        search_GTE_LTE_queryTime_DATE_RANGE = ''
        search_EQ_cstmsysId  = ''
        ret = EntResultInfoRequest.get_page(curPage,
                maxSize,
                search_EQ_enterpriseName,
                search_EQ_signCode,
                search_EQ_uniformSocialCredCode,
                search_EQ_orgInstCode,
                search_EQ_qryReason,
                search_EQ_source,
                search_EQ_status,
                search_EQ_operator,
                search_EQ_operOrg,
                search_EQ_queryFormat,
                search_GTE_LTE_queryTime_DATE_RANGE,
                search_EQ_cstmsysId,self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.list)
        return ret.list

    def id_data_more(self):
        ids_list = []
        datas = self.get_page_more()
        for data in datas:
            ids_list.append(data.id)
        ids = ids_list[:2]
        ids = ','.join(ids)
        return ids

    def get_flag_more(self):#导出前必须先获取导出标志，否则导出文件为空
        '''获取导出标志'''
        search_EQ_enterpriseName = ''
        search_EQ_signCode = ''
        search_EQ_uniformSocialCredCode = ''
        search_EQ_qryReason = ''
        search_EQ_orgInstCode = ''
        search_EQ_source = ''
        search_EQ_status = ''
        search_EQ_operator = ''
        search_EQ_operOrg = ''
        search_EQ_queryFormat = ''
        search_GTE_LTE_queryTime_DATE_RANGE = ''
        search_EQ_cstmsysId = ''
        ids = self.id_data_more()
        ret = EntResultInfoRequest.get_flag(search_EQ_enterpriseName,
                search_EQ_signCode,
                search_EQ_uniformSocialCredCode,
                search_EQ_orgInstCode,
                search_EQ_qryReason,
                search_EQ_source,
                search_EQ_status,
                search_EQ_operator,
                search_EQ_operOrg,
                search_EQ_queryFormat,
                search_GTE_LTE_queryTime_DATE_RANGE,
                search_EQ_cstmsysId,
                ids,self.cookie)
        Log.info(ret)
        self.assertEqual('允许导出',ret.msg)
        self.assertEqual('00000000',ret.code)
        return ids

    def test_d_exportload_more(self):
        '''导出2条数据'''
        search_EQ_enterpriseName = ''
        search_EQ_signCode = ''
        search_EQ_uniformSocialCredCode = ''
        search_EQ_qryReason = ''
        search_EQ_orgInstCode = ''
        search_EQ_source = ''
        search_EQ_status = ''
        search_EQ_operator = ''
        search_EQ_operOrg = ''
        search_EQ_queryFormat = ''
        search_GTE_LTE_queryTime_DATE_RANGE = ''
        search_EQ_cstmsysId = ''
        ids = self.get_flag_more()
        ret = EntResultInfoRequest.exportload(search_EQ_enterpriseName,
                search_EQ_signCode,
                search_EQ_uniformSocialCredCode,
                search_EQ_orgInstCode,
                search_EQ_qryReason,
                search_EQ_source,
                search_EQ_status,
                search_EQ_operator,
                search_EQ_operOrg,
                search_EQ_queryFormat,
                search_GTE_LTE_queryTime_DATE_RANGE,
                search_EQ_cstmsysId, ids,self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret)
        name = '企业辖内查询记录2条dhcc_ent_resultinfoDtest_d_exportload_more%s.xls' % time.strftime('%Y%m%d%H%M%S', time.localtime())
        size = download(name, ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)

    def get_flag_all(self):#导出前必须先获取导出标志，否则导出文件为空
        '''获取导出标志'''
        search_EQ_enterpriseName = ''
        search_EQ_signCode = ''
        search_EQ_uniformSocialCredCode = ''
        search_EQ_qryReason = ''
        search_EQ_orgInstCode = ''
        search_EQ_source = ''
        search_EQ_status = ''
        search_EQ_operator = ''
        search_EQ_operOrg = ''
        search_EQ_queryFormat = ''
        search_GTE_LTE_queryTime_DATE_RANGE = ''
        search_EQ_cstmsysId = ''
        ids = ''
        ret = EntResultInfoRequest.get_flag(search_EQ_enterpriseName,
                search_EQ_signCode,
                search_EQ_uniformSocialCredCode,
                search_EQ_orgInstCode,
                search_EQ_qryReason,
                search_EQ_source,
                search_EQ_status,
                search_EQ_operator,
                search_EQ_operOrg,
                search_EQ_queryFormat,
                search_GTE_LTE_queryTime_DATE_RANGE,
                search_EQ_cstmsysId,
                ids,self.cookie)
        time.sleep(8)
        Log.info(ret)
        self.assertEqual('允许导出',ret.msg)
        self.assertEqual('00000000',ret.code)
        return ids

    def test_e_exportload_all(self):
        '''导出全部数据'''
        search_EQ_enterpriseName = ''
        search_EQ_signCode = ''
        search_EQ_uniformSocialCredCode = ''
        search_EQ_qryReason = ''
        search_EQ_orgInstCode = ''
        search_EQ_source = ''
        search_EQ_status = ''
        search_EQ_operator = ''
        search_EQ_operOrg = ''
        search_EQ_queryFormat = ''
        search_GTE_LTE_queryTime_DATE_RANGE = ''
        search_EQ_cstmsysId = ''
        ids = self.get_flag_all()
        ret = EntResultInfoRequest.exportload(search_EQ_enterpriseName,
                search_EQ_signCode,
                search_EQ_uniformSocialCredCode,
                search_EQ_orgInstCode,
                search_EQ_qryReason,
                search_EQ_source,
                search_EQ_status,
                search_EQ_operator,
                search_EQ_operOrg,
                search_EQ_queryFormat,
                search_GTE_LTE_queryTime_DATE_RANGE,
                search_EQ_cstmsysId,
                ids,self.cookie)
        time.sleep(10)
        Log.info(ret)
        self.assertIsNotNone(ret)
        name = '企业辖内查询记录alldhcc_ent_resultinfoDtest_e_exportload_all%s.xls' % time.strftime('%Y%m%d%H%M%S', time.localtime())
        size = download(name, ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)






if __name__ == "__main__":
    pass